package mtn.bowen.yan.server.dao;

import mtn.bowen.yan.server.model.WeekRecipe;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author <a href=mailto:yanbowen90@foxmail.com> bowen.yan </a>
 * @version 1.0
 * @description: 本周食谱数据表
 * @date 2021-10-30 11:12 AM
 */
@Mapper
@Repository
public interface WeekRecipeDao {

    String ID = "id";

    String TABLE_NAME = "week_recipe";

    String ALL_FIELDS = "id,week,type,kind,uuid,name";

    String OTHER_FIELDS = "week,type,kind,uuid,name";

    @Select("SELECT " + ALL_FIELDS + " FROM " + TABLE_NAME)
    List<WeekRecipe> selectAll();

    @Select("SELECT " + ALL_FIELDS + " FROM " + TABLE_NAME + " WHERE week = #{week} AND type = #{type} AND kind = #{kind} ")
    List<WeekRecipe> selectByWeekAndTypeAndKind(@Param("week") Integer week, @Param("type") Integer type, @Param("kind") Integer kind);

    @Delete({"DELETE FROM " + TABLE_NAME + " WHERE week = #{week} AND type = #{type} AND kind = #{kind} "})
    int deleteByWeekAndTypeAndKind(@Param("week") Integer week, @Param("type") Integer type, @Param("kind") Integer kind);

    @Insert("INSERT INTO " + TABLE_NAME + " (" + OTHER_FIELDS + ") VALUES (#{week}, #{type}, #{kind}, #{uuid}, #{name})")
    @Options(useGeneratedKeys = true, keyColumn = ID)
    int insertWeekRecipe(WeekRecipe weekRecipe);

    @Select("SELECT " + ALL_FIELDS + " FROM " + TABLE_NAME + " WHERE week = #{week} AND type = #{type} ")
    List<WeekRecipe> selectByWeekAndType(@Param("week") Integer week, @Param("type") Integer type);
}
